package Day07_24;

public class Hotel_Management_System {
    private Room[][] rooms = new Room[3][6];

    public Hotel_Management_System() {
        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {
                if (i == 0)
                    rooms[i][j] = new Room((i + 1) * 100 + j + 1,"豪华单人间",true);
                if (i == 1)
                     rooms[i][j] = new Room((i + 1) * 100 + j + 1,"豪华双人间",true);
                if (i == 2)
                     rooms[i][j] = new Room((i + 1) * 100 + j + 1,"豪华三人间",true);
            }
        }
    }
    public Room[][] getRooms() {
        return rooms;
    }
    public void setRooms(Room[][] rooms) {
        this.rooms = rooms;
    }
    public void ReserveRoom(int roomNumber) {
        int x = roomNumber / 100 - 1;
        int y = roomNumber % 100 - 1;
        System.out.println(this.rooms[x][y].getRoomNumber() + "房间预定成功！");
        this.rooms[x][y].setRoomFree(false);
//        for (int i = 0; i < rooms.length; i++) {
//            for (int j = 0; j < rooms[i].length; j++) {
//                if (roomNumber == this.rooms[i][j].getRoomNumber() && this.rooms[i][j].getRoomFree() == true) {
//                    System.out.println(this.rooms[i][j].getRoomNumber() + "房间预定成功！");
//                    this.rooms[i][j].setRoomFree(false);
//                    return;
//                } else {
//                    if (roomNumber != this.rooms[i][j].getRoomNumber()) {
//                        System.out.println("房间号错误，请重新输入！");
//                        return;
//                    }
//                    if (roomNumber == this.rooms[i][j].getRoomNumber() && this.rooms[i][j].getRoomFree() != true) {
//                        System.out.println("房间已满，请预定其他房间！");
//                        return;
//                    }
//                }
//            }
//        }
    }
    public void Check_Out(int roomNumber){
        int x = roomNumber / 100 - 1;
        int y = roomNumber % 100 - 1;
        System.out.println(this.rooms[x][y].getRoomNumber() + "房间退订成功！");
        this.rooms[x][y].setRoomFree(true);
//        for (int i = 0; i < rooms.length; i++) {
//            for (int j = 0; j < rooms[i].length; j++) {
//                if (roomNumber == this.rooms[i][j].getRoomNumber() && this.rooms[i][j].getRoomFree() == false) {
//                    System.out.println(this.rooms[i][j].getRoomNumber() + "退房成功！");
//                    this.rooms[i][j].setRoomFree(true);
//                    return;
//                } else {
//                    if (roomNumber != this.rooms[i][j].getRoomNumber()) {
//                        System.out.println("房间号错误，请重新输入！");
//                        return;
//                    }
//                    if (roomNumber == this.rooms[i][j].getRoomNumber() && this.rooms[i][j].getRoomFree() == true) {
//                        System.out.println("房间已退，无需再退房间！");
//                        return;
//                    }
//                }
//            }
//        }
    }

    public void LookAllRoom(){

        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {

                System.out.print(this.rooms[i][j].getRoomNumber()+": "+this.rooms[i][j].getRoomType()+" "+this.rooms[i][j].getRoomFree()+"   ");
                }
            System.out.println();
            }
        }

}
